package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.TourSight;
import com.ruoyi.system.service.ITourSightService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("toursight")
@ResponseBody
public class TourSightController {

    @Resource
    private ITourSightService iTourSightService;

    @GetMapping("/list")
    public AjaxResult list() {
        try {
            List<TourSight> TourSights = iTourSightService.selectSightList();
            return AjaxResult.success(TourSights);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }

    @PostMapping("/list")
    public AjaxResult list(int cityId) {
        try {
            List<TourSight> TourSights = iTourSightService.selectSightList(cityId);
            return AjaxResult.success(TourSights);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }

    @PostMapping(path = "/create")
    public AjaxResult addSight(@RequestBody TourSight tourSight) {
        try {
            int id = iTourSightService.addSight(tourSight);
            return AjaxResult.success(id);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }

    @PostMapping(path = "/update")
    public AjaxResult updateSight(@RequestBody TourSight tourSight) {
        try {
            String Result = iTourSightService.updateSight(tourSight);
            return AjaxResult.success(Result);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }

    @PostMapping(path = "/delete")
    public AjaxResult deleteSight(int sightId) {
        try {
            String Result = iTourSightService.deleteSight(sightId);
            return AjaxResult.success(Result);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }
}
